#ifndef __XLX_SOCKET_H__
#define __XLX_SOCKET_H__

typedef void* TutuSocketHandle;

typedef struct{

    //连接成功or失败
    void (*event_connect_status)(TutuSocketHandle handle,int success);
    
    //有新数据来了
    void (*event_has_new_data)(TutuSocketHandle handle,char *data,int len);
    
    //连接出现错误
    void (*event_connect_error)(TutuSocketHandle handle,int ecode);
    
    //通知连接已经被关闭
    void (*event_connect_close)(TutuSocketHandle handle);
    
    //是否有数据包需要发送
    int (*event_need_send_data)(TutuSocketHandle handle);

    //可以发送数据包
    void (*event_can_send_data)(TutuSocketHandle handle);
}TutuSocketEvent;

//tcp连接接口
typedef struct _TuTuSocket{
    //连接服务器
    TutuSocketHandle (*tcp_connect)(const char *szIp,int port,TutuSocketEvent *event);

    //循环事件
    void (*socket_loop)();

    //关闭连接
    void (*socket_close)(TutuSocketHandle handle);

    //发送数据
    int (*socket_write)(TutuSocketHandle handle,char *data,int len);

    //设置用户数据
    void (*set_user_data)(TutuSocketHandle handle,void *data);

    //获取用户数据
    void* (*get_user_data)(TutuSocketHandle handle);
}TutuSocket;

//初始化
void TutuSocket_Init(TutuSocket *myself);

#endif